package com.ruoyi.challenge_cup.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.challenge_cup.domain.ChallengeCup;
import com.ruoyi.challenge_cup.service.IChallengeCupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 挑战杯Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/challenge_cup/challenge_cup")
public class ChallengeCupController extends BaseController
{
    @Autowired
    private IChallengeCupService challengeCupService;

    /**
     * 查询挑战杯列表
     */
    @PreAuthorize("@ss.hasPermi('challenge_cup:challenge_cup:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChallengeCup challengeCup)
    {
        startPage();
        List<ChallengeCup> list = challengeCupService.selectChallengeCupList(challengeCup);
        return getDataTable(list);
    }

    /**
     * 导出挑战杯列表
     */
    @PreAuthorize("@ss.hasPermi('challenge_cup:challenge_cup:export')")
    @Log(title = "挑战杯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChallengeCup challengeCup)
    {
        List<ChallengeCup> list = challengeCupService.selectChallengeCupList(challengeCup);
        ExcelUtil<ChallengeCup> util = new ExcelUtil<ChallengeCup>(ChallengeCup.class);
        util.exportExcel(response, list, "挑战杯数据");
    }

    /**
     * 获取挑战杯详细信息
     */
    @PreAuthorize("@ss.hasPermi('challenge_cup:challenge_cup:query')")
    @GetMapping(value = "/{ccId}")
    public AjaxResult getInfo(@PathVariable("ccId") Long ccId)
    {
        return success(challengeCupService.selectChallengeCupByCcId(ccId));
    }

    /**
     * 新增挑战杯
     */
    @PreAuthorize("@ss.hasPermi('challenge_cup:challenge_cup:add')")
    @Log(title = "挑战杯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChallengeCup challengeCup)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        challengeCup.setDeptId(105L);
        challengeCup.setUserId(user.getUserId());
        return toAjax(challengeCupService.insertChallengeCup(challengeCup));
    }

    /**
     * 修改挑战杯
     */
    @PreAuthorize("@ss.hasPermi('challenge_cup:challenge_cup:edit')")
    @Log(title = "挑战杯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChallengeCup challengeCup)
    {
        return toAjax(challengeCupService.updateChallengeCup(challengeCup));
    }

    /**
     * 删除挑战杯
     */
    @PreAuthorize("@ss.hasPermi('challenge_cup:challenge_cup:remove')")
    @Log(title = "挑战杯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ccIds}")
    public AjaxResult remove(@PathVariable Long[] ccIds)
    {
        return toAjax(challengeCupService.deleteChallengeCupByCcIds(ccIds));
    }
}
